/*
 * =====================================================================================
 *
 *       Filename:  readalbe_timeo.cpp
 *
 *    Description:  利用select做超时
 *
 *        Version:  1.0
 *        Created:  2008年09月05日 13时27分57秒
 *       Revision:  none
 *       Compiler:  g++
 *
 *         Author:  ZhixiongHong (hzx), fishwarter@gmail.com
 *        Company:  Unioncast
 *
 * =====================================================================================
 */


#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>


int readable_timeo(int fd, int ms)
{
	fd_set	rset;

	FD_ZERO(&rset);
	FD_SET(fd, &rset);
	
	struct timeval 	tv;
	tv.tv_sec = ms/1000;
	tv.tv_usec = ms%1000;
	
	int ret = select(fd+1, &rset, NULL, NULL, &tv);
	return ret; /* >0 if descriptor is readable */
}
